package net.hn.hnms.biz.shipped.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import net.hn.hnms.biz.api.plan.model.RailroadLoadingDto;
import net.hn.hnms.biz.shipped.domain.Vo.RailroadLoadingVo;
import net.hn.hnms.biz.shipped.service.RailroadLoadService;
import net.hn.hnms.sys.common.core.domain.R;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Date;

@Api(value = "铁路装车", tags = {"铁路装车"})
@RestController
@RequestMapping("/railroadload")
public class RailroadLoadController {

    @Resource
    private RailroadLoadService railroadLoadService;
    @ApiOperation("获取年总重和上月数据")
    @GetMapping("/yearRealWeightAndlastMonthSum")
//    @AutoSetMineCode
    public R<RailroadLoadingVo> yearRealWeightAndlastMonthSum(@ApiParam(value = "煤矿编码") String mineCode) {
        RailroadLoadingVo railroadLoadingVo = railroadLoadService.yearRealWeightAndlastMonthSum(mineCode);
        return R.ok(railroadLoadingVo);
    }

    /**
     * 保存铁路装车
     * @param
     * @return
     */

    @GetMapping("/saveRailroadload")
    public R<Boolean> saveRailroadload(String  yearTime,String  yearRealWeight, String  lastMonthTime, String  lastMonthSum, Date dataTime, String StringDataTime) {
        RailroadLoadingDto railroadLoadingDto = new RailroadLoadingDto();
//        railroadLoadingDto.setYearTime(yearTime);
//        railroadLoadingDto.setYearRealWeight(yearRealWeight);
//        railroadLoadingDto.setLastMonthTime(lastMonthTime);
//        railroadLoadingDto.setLastMonthSum(lastMonthSum);
////        railroadLoadingDto.setDataTime(dataTime);
        //dataTime获取的时间不对 需要修改
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        try {
            Date parse = simpleDateFormat.parse(StringDataTime);
            railroadLoadingDto.setDataTime(parse);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }

        Boolean is = railroadLoadService.saveRailroadload(railroadLoadingDto);
        return R.ok(is);
    }

}
